﻿//
// PositionRepository.cs
//
// Authors:
//    Lasse Andreas Hauge Petersen <09547@iha.dk>
//    Søren Flohr Nielsen <10638@iha.dk>
//    Claus Jørgensen <10229@iha.dk>
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Data.Objects;
using System.Diagnostics.Contracts;

namespace RSD.Data
{
    /// <summary>
    /// Represents a Position Repository.
    /// </summary>
    [ContractClass(typeof(Contracts.IPositionRepositoryContract))]
    public interface IPositionRepository : IRepository<Position>
    {
        /// <summary>
        /// Gets a position from a given vector name.
        /// </summary>
        /// <param name="vectorName">Name of the vector.</param>
        /// <returns>The matched position; otherwise <c>null</c>.</returns>
        Position GetPositionByName(string vectorName);        
    }

    /// <summary>
    /// Represents a Position Repository.
    /// </summary>
    public sealed class PositionRepository : RepositoryBase<Position>, IPositionRepository
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PositionRepository"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public PositionRepository(IObjectContext context)
            : base(context)
        {
            Contract.Requires(context != null);
        }

        #region IPositionRepository Members

        /// <summary>
        /// Gets a position from a given vector name.
        /// </summary>
        /// <param name="vectorName">Name of the vector.</param>
        /// <returns>
        /// The matched position; otherwise <c>null</c>.
        /// </returns>
        public Position GetPositionByName(string vectorName)
        {
            return FindBy(x => x.Name == vectorName).FirstOrDefault();
        }

        #endregion
    }
}
